//
// Time-stamp: <94/12/01 19:31:12 stephan>
//
//	MiscClassDecoderMgr.m -- application's delegate.
//	
//		Written by Stephan Wacker <stephan@rodion.muc.de>
//		Copyright (c) 1994 by Stephan Wacker.
//		Version 1.0  All rights reserved.
//
//		This notice may not be removed from this source code.
//
//	This object is included in the MiscKit by permission from the author
//	and its use is governed by the MiscKit license, found in the file
//	"LICENSE.rtf" in the MiscKit distribution.  Please refer to that file
//	for a list of all applicable permissions and restrictions.
//	


#import "MiscClassDecoderMgr.h"

#import "MiscClassDecoderSetup.h"	// from a bundle
#import <misckit/MiscClassDecoder.h>


@implementation MiscClassDecoderMgr


- defineClass: (id) pasteboard 
    userData: (const char *) userData 
    error: (char **) msg
// Service for defining a given class.
{
    char 	*data, *buf;
    int 	length;
    
    // Pretend to check the pasteboard types.
    //
    [pasteboard types];
    
    // Read the ASCII data from the pasteboard.
    //
    if( [pasteboard readType: NXAsciiPboardType data: &data
	 length: &length] )
    {
        buf = alloca( length+1 );
        strncpy( buf, data, length );
        buf[length] = '\0';
	[decoder analyzeClass: buf];
    }
    else
    {
	*msg = "Error: couldn't read class name from pasteboard.";
    }
    
    return self;
}


- appDidInit: sender
// Install decoder service.
{
    const char	*myDirectory = [[NXBundle mainBundle] directory];
    const char	*bundleSubdir = "/MiscClassDecoder.bundle";
    char	*buf = (char *) alloca(  strlen(myDirectory)
				       + strlen(bundleSubdir) + 1 );

    strcpy( buf, myDirectory );
    strcat( buf, bundleSubdir );
    
    // Load a decoder window from the bundle.
    //
    decoder = [[[ [[NXBundle alloc]
		   initForDirectory: buf]
		 classNamed: "MiscClassDecoderSetup"] new] decoder];

    // Accept service requests.
    //
    [[NXApp appListener] setServicesDelegate: self];

    return self;
}


@end	// MiscClassDecoderMgr
